// Decompiled by JAD v1.5.4.2. Copyright 1997-98 Pavel Kouznetsov.
// JAD Home Page:      http://web.unicom.com.cy/~kpd/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Zoop.java

import java.applet.Applet;

class OpponentThread extends Thread
{

    OpponentThread(ZoopDisplay zoopdisplay, Applet applet)
    {
        fHasntLost = true;
        fPlayAgain = true;
        zd = zoopdisplay;
        theApplet = applet;
    }

    public void run()
    {
        boolean flag = true;
        while(fPlayAgain) 
        {
            for(int i = 0; i < 3 && fHasntLost;)
            {
                if(i != 1)
                    zd.clearBoard();
                if(flag)
                    flag = false;
                else
                    zd.setColors(i);
                zd.setPiecesRemaining(30);
                for(fMorePieces = fHasntLost = true; fMorePieces && fHasntLost;)
                {
                    byte byte0 = (byte)(int)(Math.random() * 16D);
                    try
                    {
                        Thread.sleep(rgiSleepTimeFromLevel[i]);
                    }
                    catch(InterruptedException ex) {}
                    byte byte2 = zd.ContentsFromChannel(byte0);
                    byte byte1;
                    if(byte2 <= 1 || Math.random() > rgfDifficultyFromLevel[i])
                        byte1 = (byte)(int)(Math.random() * 4D);
                    else
                        byte1 = (byte)(byte2 & 0x3);
                    fHasntLost = zd.InsertPiece(byte0, byte1);
                    fMorePieces = zd.FPiecesRemaining();
                    if(!fHasntLost)
                        zd.ShowLost();
                }

                switch(i)
                {
                case 1: /* '\001' */
                    if(fHasntLost)
                    {
                        zd.SetPromptMode(0);
                        int j;
                        while((j = zd.CheckPromptMode()) == 0) 
                            try
                            {
                                Thread.sleep(100L);
                            }
                            catch(InterruptedException ex) {}

                        if(j == 1)
                            fHasntLost = false;
                    }
                    // fall through

                case 0: /* '\0' */
                case 2: /* '\002' */
                default:
                    i++;
                    break;

                }
            }

            zd.SetPromptMode(1);
            int k;
            while((k = zd.CheckPromptMode()) == 0) 
                try
                {
                    Thread.sleep(100L);
                }
                catch(InterruptedException ex) {}

            if(fPlayAgain = k == 2)
            {
                fHasntLost = true;
                zd.InitGame();
            }
        }

        zd.GameOver();
    }

    private ZoopDisplay zd;
    private boolean fMorePieces;
    private boolean fHasntLost;
    private boolean fPlayAgain;
    private Applet theApplet;
    private static final int rgiSleepTimeFromLevel[] = {
        1000, 700, 300
    };
    private static final double rgfDifficultyFromLevel[] = {
        0.84999999999999998D, 0.65000000000000002D, 0.45000000000000001D
    };
    private static final int iLevels = 3;

}
